package com.huawei.hwid.api.common;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.RemoteException;
import com.huawei.cloudservice.CloudAccountManager;
import com.huawei.cloudservice.LogoutHandler;
import com.huawei.cloudservice.c;
import com.huawei.cloudservice.c.a;
import com.huawei.hwid.core.d.b.e;
import com.huawei.hwid.core.helper.handler.ErrorStatus;

public class m extends b {
    private String d;
    private Bundle e;
    private String f;
    private LogoutHandler g;
    private Context h;

    public m(Context context, String str, String str2, Bundle bundle, LogoutHandler logoutHandler) {
        super(context);
        this.h = context;
        this.d = str;
        this.f = str2;
        this.e = bundle;
        this.g = logoutHandler;
    }

    void b() {
        a a = a.a(this.h);
        if (a == null) {
            e.d("LogoutTask", "cloudAccount logout null == aidlClientManager", true);
            return;
        }
        try {
            a.a().a(this.d, this.f, this.e, a(this.g));
        } catch (RemoteException e) {
            e.d("LogoutTask", "login remote exception", true);
        }
    }

    void a(ErrorStatus errorStatus) {
        if (errorStatus == null) {
            errorStatus = new ErrorStatus(39, "login timeout. retry again");
        }
        this.g.onFail(errorStatus);
    }

    private c a(final LogoutHandler logoutHandler) {
        return new a(this) {
            final /* synthetic */ m b;

            public void a(int i, Bundle bundle) throws RemoteException {
            }

            public void a(int i, Intent intent) throws RemoteException {
            }

            public void a(int i) throws RemoteException {
                e.b("LogoutTask", "logoutResult", true);
                if (this.b.b.get()) {
                    e.b("LogoutTask", "has cancelled by timeout, return directly", true);
                    return;
                }
                if (i == 6) {
                    CloudAccountManager.clearAccountData(this.b.h);
                    logoutHandler.onSuccess();
                } else if (i == 0) {
                    logoutHandler.onFail(new ErrorStatus(31, "Account has not login"));
                } else if (i == 7) {
                    logoutHandler.onFail(new ErrorStatus(42, "userid not system account"));
                } else if (i == 8) {
                    logoutHandler.onFail(new ErrorStatus(44, "packagename was not matched"));
                } else if (i == 9) {
                    logoutHandler.onFail(new ErrorStatus(43, "packagename not in hwid list"));
                } else if (i == 1) {
                    logoutHandler.onFail(new ErrorStatus(29, "Signature invalid"));
                } else {
                    logoutHandler.onFail(new ErrorStatus(44, "other error"));
                    e.b("LogoutTask", "DONT KNOW RET_CODE:", true);
                }
                this.b.a();
            }

            public void b(int i, Bundle bundle) throws RemoteException {
            }
        };
    }

    public String toString() {
        return "LogoutTask{  mServiceType='" + this.d + '\'' + '}';
    }
}
